package com.zhaoxi.project.hrp.controller;

import com.zhaoxi.framework.aspectj.lang.annotation.Log;
import com.zhaoxi.framework.aspectj.lang.enums.BusinessType;
import com.zhaoxi.framework.web.BaseService;
import com.zhaoxi.framework.web.PageData;
import com.zhaoxi.project.hrp.service.UserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

// * 样例信息操作处理
@Tag(name = "系统用户管理")
@RestController
@RequestMapping("/hrp/user")
public class UserController extends BaseService {
  
  @Autowired
  private UserService userService;
  
  //  获列表
  @PreAuthorize("@ss.hasPermi('hrp:user:list')")
  @GetMapping("/getList")
  public PageData getList(Map map) {
    PageData pd = this.getPageData(map);
    //如果 pageNum 和 pageSize 都是有值的，就是需要分页的
    if (pd.getLong("pageNum") != null && pd.getLong("pageSize") != null){
      this.startPage();
    }
    return this.responses(userService.getList(pd));
  }

  //  新增
  @PreAuthorize("@ss.hasPermi('hrp:user:add')")
  @Log(title = "用户管理", businessType = BusinessType.INSERT)
  @PostMapping
  public PageData addUser(@RequestBody Map map) {
    PageData pd = this.getPageData(map);
    return userService.addUser(pd);
  }

  //  修改
  @Operation(summary = "设置系统登录账号和密码，")
  @PreAuthorize("@ss.hasPermi('hrp:user:loginName')")
  @Log(title = "系统用户账户管理", businessType = BusinessType.UPDATE)
  @PutMapping("/editLoginName")
  public PageData editLoginName(@RequestBody Map map) {
    PageData pd = this.getPageData(map);
    return userService.editLoginName(pd);
  }

  //  修改
  @PreAuthorize("@ss.hasPermi('hrp:user:edit')")
  @Log(title = "用户管理", businessType = BusinessType.UPDATE)
  @PutMapping
  public PageData edit(@RequestBody Map map) {
    PageData pd = this.getPageData(map);
    return userService.edit(pd);
  }

  //  删除
  @PreAuthorize("@ss.hasPermi('hrp:user:del')")
  @Log(title = "用户管理", businessType = BusinessType.DELETE)
  @DeleteMapping("id/{id}")
  public PageData del(@PathVariable Long id) {
    return userService.del(id);
  }
  
}
